package com.crm.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crm.crm.domain.Activity;
import com.crm.crm.domain.dto.PageQueryParams;
import com.crm.crm.domain.vo.PageResult;
import com.crm.crm.mapper.ActivityMapper;
import com.crm.crm.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crm.crm.service.ActivityService;

import java.util.List;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    //分页查询
    @Override
    public PageResult<Activity> pageQuery(PageQueryParams pageQueryParams) {
        Page<Activity> page = new Page<>(pageQueryParams.getPageNum(),pageQueryParams.getPageSize());
        LambdaQueryWrapper<Activity> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(pageQueryParams.getId()),Activity::getCode,pageQueryParams.getId())
                .eq(pageQueryParams.getChannel()!=null,Activity::getChannel,pageQueryParams.getChannel())
                .between(pageQueryParams.getBegin()!=null&&pageQueryParams.getEnd()!=null,
                        Activity::getCreateTime,pageQueryParams.getBegin(),pageQueryParams.getEnd())
                .between(pageQueryParams.getBegin()!=null&&pageQueryParams.getEnd()!=null,
                        Activity::getBeginTime,pageQueryParams.getBegin(),pageQueryParams.getEnd());
        Page<Activity> result = getBaseMapper().selectPage(page,wrapper);
        return new PageResult<>(result.getTotal(),result.getRecords());
    }

    @Override
    public List<Activity> selectListByType(Integer type) {
       List<Activity> list = activityMapper.selectListByType(type.toString());
        return list;
    }
}
